package cn.xie.blog.webadmin.web.handler;

import cn.xie.blog.commonutil.response.Response;
import cn.xie.blog.serverutil.exception.BlogException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author: xiaoxie
 * create: 2025-05-01 23:17
 * @BelongsProject: blog-parent
 * @BelongsPackage: cn.xie.blog.webadmin.web.handler
 * description: 全局异常处理
 */
@ControllerAdvice
public class GlobalExceptionHandler {

    private static final Logger log = LoggerFactory.getLogger(GlobalExceptionHandler.class);

    @ExceptionHandler(BlogException.class)
    @ResponseBody
    public Response<?> handleServiceException(BlogException e) {
        log.error("内部异常",e);
        return Response.error(e.getCode(), e.getMessage());
    }
    @ExceptionHandler(Exception.class)
    @ResponseBody
    public Response<?> handleException(Exception e) {
        log.error("内部异常 e:{}",e.getMessage());
        return Response.error(500000,"系统内部错误,请重试");
    }
}
